import java.time.LocalDateTime;
import java.time.ZoneId;
import java.time.ZonedDateTime;
import java.time.format.DateTimeFormatter;

public class Credit {
    long getConversationTime(ZonedDateTime time,int fastConversionCount,int delayConversionCount,boolean hasConversion){
        int month=time.getMonthValue();
        int day=time.getDayOfMonth();
        int hour=time.getHour();
        int dayOfWeek=time.getDayOfWeek().getValue();
        boolean isNeedSunday=false;
        if(month==3&&dayOfWeek==7&&day-7*fastConversionCount<1&&hour>=3&&hasConversion){
            isNeedSunday=true;
            return time.toEpochSecond()-60*60;
        }
        if(month==11&&dayOfWeek==7&&day-7*delayConversionCount<1&&hasConversion){
            return time.toEpochSecond()+60*60;
        }
        return time.toEpochSecond();
    }

    public double calculateCost(String startTimeStr, String endTimeStr,int fastConversionCount,int delayConversionCount,boolean startHasConversion,boolean endHasConversion) {
        double cost=0;
        LocalDateTime startTime = LocalDateTime.parse(startTimeStr, DateTimeFormatter.ofPattern("yyyy-MM-dd HH:mm:ss"));
        LocalDateTime endTime = LocalDateTime.parse(endTimeStr, DateTimeFormatter.ofPattern("yyyy-MM-dd HH:mm:ss"));
        ZonedDateTime startZonedTime = ZonedDateTime.of(startTime, ZoneId.systemDefault());
        ZonedDateTime endZonedTime = ZonedDateTime.of(endTime, ZoneId.systemDefault());
        long realStartTime=getConversationTime(startZonedTime,fastConversionCount,delayConversionCount,startHasConversion);
        long realEndTime=getConversationTime(endZonedTime,fastConversionCount,delayConversionCount,endHasConversion);
        double duration=Math.ceil((realEndTime-realStartTime)/60.0);
        if(duration>0&&duration<=20.0){
            cost=duration*0.05;
        }else if(duration>20.0){
            cost=1.0+(duration-20.0)*0.10;
        }
        return cost;
    }

}
